manager.js ➔ ... ➔ getInstance   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
/*
2
 * This file is part of Sulu.
3
 *
4
 * (c) MASSIVE ART WebServices GmbH
5
 *
6
 * This source file is subject to the MIT license that is bundled
7
 * with this source code in the file LICENSE.
8
 */
9
10
define(['underscore', 'jquery', 'services/husky/util'], function(_, $, Util) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
11
12
    'use strict';
13
14
    var instance = null,
15
16
        getInstance = function() {
17
            if (instance === null) {
18
                instance = new ThreadManager();
19
            }
20
            return instance;
21
        },
22
23
        url = _.template('/admin/api/threads<% if (typeof id !== "undefined") { %>/<%= id %><% } %>');
24
25
    /** @constructor **/
26
    function ThreadManager() {
27
    }
28
29
    ThreadManager.prototype = {
30
        load: function(id) {
31
            return Util.load(url({id: id}));
32
        },
33
        save: function(data) {
34
            return Util.save(url({id: data.id}), !!data.id ? 'PUT' : 'POST', data);
35
        },
36
        delete: function(id) {
37
            return Util.save(url({id: id}), 'DELETE');
38
        },
39
        deleteMultiple: function(ids) {
40
            return Util.save(url() + '?ids=' + ids.join(','), 'DELETE');
41
        },
42
        url: url
43
    };
44
45
    return getInstance();
46
});
47